home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 6.3 KB | 314 lines | [TEXT/CWIE] |
- // SequenceLoop.cp
-
- #ifndef SequenceLoop_h
- #include "SequenceLoop.h"
- #endif
- #ifndef Sequence_h
- #include "Sequence.h"
- #endif
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list )
- : position( list.First() ),
- next( 0 ),
- previous( 0 ),
- head( list ),
- nextLoop( 0 )
- {
- finished = ( position == 0 );
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list, AtStart )
- : position( list.First() ),
- next( 0 ),
- previous( 0 ),
- head( list ),
- nextLoop( 0 )
- {
- finished = ( position == 0 );
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list, AtEnd )
- : position( list.Last() ),
- next( 0 ),
- previous( 0 ),
- head( list ),
- nextLoop( 0 )
- {
- finished = ( position == 0 );
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list, Nowhere )
- : position( 0 ),
- next( 0 ),
- previous( 0 ),
- head( list ),
- nextLoop( 0 ),
- finished( true )
- {
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list,
- const Node& thePosition )
- : position( &thePosition ),
- next( 0 ),
- previous( 0 ),
- head( list ),
- nextLoop( 0 ),
- finished( false )
- {
- Assert( thePosition.Owned() );
- Assert( &head == &thePosition.Owner() );
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list,
- Before,
- const Node& thePosition )
- : position( 0 ),
- next( &thePosition ),
- previous( thePosition.Previous() ),
- head( list ),
- nextLoop( 0 ),
- finished( false )
- {
- Assert( thePosition.Owned() );
- Assert( &head == &thePosition.Owner() );
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list,
- After,
- const Node& thePosition )
- : position( 0 ),
- next( thePosition.Next() ),
- previous( &thePosition ),
- head( list ),
- nextLoop( 0 ),
- finished( false )
- {
- Assert( thePosition.Owned() );
- Assert( &head == &thePosition.Owner() );
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list, BeforeStart )
- : position( 0 ),
- next( list.First() ),
- previous( 0 ),
- head( list ),
- nextLoop( 0 ),
- finished( false )
- {
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Head& list, AfterEnd )
- : position( 0 ),
- next( 0 ),
- previous( list.Last() ),
- head( list ),
- nextLoop( 0 ),
- finished( false )
- {
- list.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::SequenceLoop( const Loop& source )
- : position( source.position ),
- next( source.next ),
- previous( source.previous ),
- head( source.head ),
- nextLoop( 0 ),
- finished( source.finished )
- {
- head.Register( *this );
- }
-
- template < class Head, class Node >
- SequenceLoop<Head,Node>::~SequenceLoop()
- {
- head.Unregister( *this );
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveToFinish()
- {
- position = 0;
- previous = 0;
- next = 0;
- finished = true;
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveToFirst()
- {
- position = head.First();
- next = 0;
- previous = 0;
- finished = (position == 0);
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveToLast()
- {
- position = head.Last();
- next = 0;
- previous = 0;
- finished = (position == 0);
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveTo( const Node& thePosition )
- {
- Assert( thePosition.Owned() );
- Assert( &head == &thePosition.Owner() );
-
- position = &thePosition;
- next = 0;
- previous = 0;
- finished = false;
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveBefore( const Node& thePosition )
- {
- Assert( thePosition.Owned() );
- Assert( &head == &thePosition.Owner() );
-
- position = 0;
- next = &thePosition;
- previous = thePosition.Previous();
- finished = false;
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveAfter( const Node& thePosition )
- {
- Assert( thePosition.Owned() );
- Assert( &head == &thePosition.Owner() );
-
- position = 0;
- next = thePosition.Next();
- previous = &thePosition;
- finished = false;
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveBeforeFirst()
- {
- position = 0;
- next = head.First();
- previous = 0;
- finished = false;
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::MoveAfterLast()
- {
- position = 0;
- next = 0;
- previous = head.Last();
- finished = false;
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::operator=( const Loop& source )
- {
- Assert( &head == &source.head );
-
- position = source.position;
- next = source.next;
- previous = source.previous;
- finished = source.finished;
- }
-
- template < class Head, class Node >
- bool SequenceLoop<Head,Node>::operator==( const Loop& right ) const
- {
- Assert( &head == &right.head );
-
- return position == right.position
- && previous == right.previous
- && next == right.next
- && finished == right.finished;
- }
-
- template < class Head, class Node >
- bool SequenceLoop<Head,Node>::operator==( const Node& right ) const
- {
- Assert( right.Owned() );
- Assert( &head == &right.Owner() );
-
- return position == &right;
- }
-
- template < class Head, class Node >
- const Node *SequenceLoop<Head,Node>::Next() const
- {
- Assert( Unfinished() );
-
- if ( position == 0 )
- return next;
- else
- return position->Next();
- }
-
- template < class Head, class Node >
- const Node *SequenceLoop<Head,Node>::Previous() const
- {
- Assert( Unfinished() );
-
- if ( position == 0 )
- return previous;
- else
- return position->Previous();
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::operator++()
- {
- Assert( Unfinished() );
-
- if ( position == 0 )
- {
- position = next;
- next = 0;
- previous = 0;
- }
- else
- position = position->Next();
-
- finished = ( position == 0 );
- }
-
- template < class Head, class Node >
- void SequenceLoop<Head,Node>::operator--()
- {
- Assert( Unfinished() );
-
- if ( position == 0 )
- {
- position = previous;
- next = 0;
- previous = 0;
- }
- else
- position = position->Previous();
-
- finished = ( position == 0 );
- }
-